/**
 * col_imgs
 */
layui.define(['YunjColsTemplet','jquery','yunj'], function (exports) {

    let YunjColsTemplet = layui.YunjColsTemplet;
    let doc = document;
    let $ = layui.jquery;

    class YunjColsTempletImgs extends YunjColsTemplet{

        constructor(options) {
            super(options);
        }

        layout(){
            let that=this;
            return `{{# 
                         let imgs = d.${that.key};
                         if(yunj.isString(imgs)) imgs = imgs.length>0?imgs.split(","):[];
                         if(!yunj.isArray(imgs)) imgs = [];
                     }}
                     {{# for(let i = 0,l = imgs.length;i < l;i++){ }}
                            {{#  if(d.is_export){  }}
                            {{ (i>0?'、':'')+imgs[i] }}
                            {{#  }else{  }}
                            <img class="table-row-imgs-item" src="{{ imgs[i] }}" alt="" title="点击预览">
                            {{#  }  }}
                     {{# } }}
                     {{#  if(imgs.length === 0&&!d.is_export){ }}
                            <img class="table-row-imgs-item" src="${that.args.default}" alt="123" title="点击预览">
                     {{#  } }}`;
        }

        defineExtraEventBind(){
            let that=this;

            $(doc).on('click','.table-row-imgs-item',function () {
                let currItemEl=$(this);
                let srcArr=[];
                currItemEl.parent().find('.table-row-imgs-item').each(function () {
                    srcArr.push($(this).attr('src'));
                });
                if(srcArr.length<=0) return false;
                let idx=srcArr.indexOf(currItemEl.attr('src'));
                if(idx===-1) idx=0;
                yunj.previewImg(srcArr,idx);
            });
        }

    }

    exports('col_imgs', YunjColsTempletImgs);
});